// start和step都是三元组。所以整三次
const calcTransition = (start, end, step) => {
  const [rS, gS, bS] = start
  const [rE, gE, bE] = end
  const diffArr = [rE-rS, gE-gS, bE-bS].map(e => e / step)
  const res = []
  for (let i=1; i<=step; i+=1) {
    res.push(
      transitionHelper(start, diffArr, i)
    )
  }
  return res
}

const rgbization = rgb => rgb.map(e => e.reduce((p,c) => p + c.toString(16).padStart(2, '0'), '#'))

const transitionHelper = (start, diff, seq) => diff.map((e, i) => start[i] + Math.floor(e * seq))

const rgb2arr = rgbStr => {
  const len = rgbStr.length
  if(len === 7) {
    rgbStr = rgbStr.slice(1)
  }
  if(len < 6) {
    return [0,0,0]
  }
  return rgbStr.split('').reduce((p, c, i) => {
    if(i % 2) {
      p.push(Number('0x' + p.pop() + c))
    } else {
      p.push(c)
    }
    return p
  }, [])
}

/*
  投标评分公式
*/
const getBase = (...args) => {
  return Math.floor(args.reduce((p,c) => p+c, 0)/args.length)
}

const baseScore = 10

const getCost = (base, price) => {
  const highFlag = price > base
  const diff = Math.abs(base - price)
  const ratio = Math.round((diff / base) * 100)
  return baseScore - (highFlag ? 0.2 : 0.18) * ratio
}